package com.flyfox.modules.hr.model;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.flyfox.util.cache.Cache;
import com.flyfox.util.cache.CacheManager;

public class SalaryItemCache {

	private final static Logger log = Logger.getLogger(SalaryItemCache.class);
	private final static String cacheName = "SalaryItemCache";
	private static Cache cache;

	/**
	 * 初始化
	 * 
	 * 2014年10月16日 上午11:21:03 flyfox 330627517@qq.com
	 */
	public static void init() {
		if (cache == null) {
			cache = CacheManager.get(cacheName);
		}
		log.info("####薪酬项目Cache初始化......");
		SalaryItemCache.initItem();
	}

	public static void initItem() {
		Map<Integer, SalaryItemCacheObj> itemMap = new LinkedHashMap<Integer, SalaryItemCacheObj>();

		List<SalaryItem> listItem = SalaryItem.dao.findByWhere(" order by sort");
		SalaryItemCacheObj obj = null;
		for (SalaryItem item : listItem) {
			int itemType = item.getInt("item_type");
			obj = itemMap.get(itemType);
			if (obj == null)
				obj = new SalaryItemCacheObj();
			obj.add(item);
			itemMap.put(itemType, obj);
		}
		cache.add("map", itemMap);
	}

	public static Map<Integer, SalaryItemCacheObj> getCacheMap() {
		return cache.get("map");
	}

	public static SalaryItemCacheObj getCacheObj(Integer itemType) {
		return getCacheMap().get(itemType);
	}
}